import java.io.File;
import java.io.StringWriter;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;


public class Compara {

	public static String transformar() throws Exception 
	{ 
		String xslA = "C:/Users/Usuario/Desktop/Ficheros/compare.xsl"; 
		String path = "C:/Users/Usuario/Desktop/Ficheros/";
		File directorio = new File(path);
		String [] ficheros = directorio.list();
	    Source xsltSource = new StreamSource(new File(xslA));
		
		String texto = "";
		for (int i = 0; i < ficheros.length; i++) {
			String xslfich1 = ficheros[i];
			for(int j = 0; j < ficheros.length; j++){
				 String xslfich2 = ficheros[j];
				  
				 StringWriter cadenaSalida = new StringWriter(); 
				 StreamResult bufferResultado = new StreamResult(cadenaSalida); 
			
				 TransformerFactory factoriaTrans = TransformerFactory.newInstance(); 
				 Transformer transformador = factoriaTrans.newTransformer(xsltSource);
				 Source xsltcmp = new StreamSource(new File(path+xslfich2));
			
				 transformador.setParameter("documentoA", xslfich1);
	             transformador.transform(xsltcmp, bufferResultado);
	             
	             texto += "Comparando... " + xslfich1 + " con " + xslfich2 + ": " + cadenaSalida.toString() + "\n"; 
			}
		}
		return texto;
	} 
	
	public static void main(String[] args) throws Exception {
		System.out.println(transformar());
	}

}
